package com.jboy.test;

public class HashCodeConflictExample {
    private String id;

    public HashCodeConflictExample(String id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        HashCodeConflictExample that = (HashCodeConflictExample) obj;
        return id.equals(that.id); // 仅根据id判断相等性
    }

    // 故意不重写hashCode()方法

    public static void main(String[] args) {
        HashCodeConflictExample a = new HashCodeConflictExample("123");
        HashCodeConflictExample b = new HashCodeConflictExample("123");

        System.out.println("equals结果: " + a.equals(b)); // 输出true
        System.out.println("a的hashCode: " + a.hashCode()); // 默认内存地址哈希值
        System.out.println("b的hashCode: " + b.hashCode()); // 不同内存地址哈希值
    }
}
